﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblCategoriesDAO
    {
        private DBService _db = null;

        public TblCategoriesDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }
        public DataTable InsUp(TblCategories cate, int mode)
        {
            DataTable dt = null;

            try
            {
                dt = _db.ExeSP_DataTable("sp_TblCategories_InUp",
                    new string[] { "@CateID", "@CateName", "@CateDescription", "@ImageURL", "@IDGroup", "@IdLang", "@IdPhanLoai", "@Mode" },
                    new object[] { cate.CateID, cate.CateName, cate.CateDescription, cate.ImageURL, cate.IDGroup, cate.IdLang, cate.IdPhanLoai ,mode },
                    CommandType.StoredProcedure);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetAll()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_TblCategories_List", false, CommandType.StoredProcedure);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetCategories_ByID(int CateID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblCategories where CateID = @CateID",
                    new string[]{"@CateID"},
                    new object[] {CateID}, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
    }
}
